package com.dykj.fireFighting.web.base.emergency;


import com.dykj.fireFighting.api.base.emergency.entity.EmergencyPlanTwo;
import com.dykj.fireFighting.api.base.emergency.service.IEmergencyPlanTwoService;
import com.dykj.fireFighting.api.base.enterprise.entity.Enterprise;
import com.dykj.fireFighting.api.base.enterprise.service.IEnterpriseService;
import com.dykj.fireFighting.common.core.api.CommonResult;
import com.dykj.fireFighting.common.core.dto.CommonDto;
import com.dykj.fireFighting.common.core.vo.LoginUserVo;
import com.dykj.fireFighting.common.core.vo.PageVo;
import com.dykj.fireFighting.web.base.shiro.ShiroUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Api(value = "应急预案新版接口", tags = {"应急预案新版接口"})
@RestController
@RequestMapping("/emergencyPlanTwo/statistic")
public class EmergencyPlanTwoStatisticController {
    @DubboReference
    private IEmergencyPlanTwoService emergencyPlanTwoService;
    @DubboReference
    private IEnterpriseService iEnterpriseService;


    @GetMapping("/rankScore")

    public CommonResult rankScore(String start,String end,String type,String shudi) {
        List<String> list=getSocial();

        return CommonResult.success(emergencyPlanTwoService.rankScore(start,end,type,shudi,list));
    }
    @GetMapping("/typeUnit")
    public CommonResult typeUnit(String start,String end,String type,String shudi)
    {
        List<String> list=getSocial();

        return CommonResult.success(emergencyPlanTwoService.typeUnit(start,end,type,shudi,list));
    }

    @GetMapping("/type")
    public CommonResult type(String start,String end,String shudi)
    {
        List<String> list=getSocial();

        return CommonResult.success(emergencyPlanTwoService.type(start,end,shudi,list));
    }


    public List<String> getSocial()
    {
        List<String> list=new ArrayList<>();
        //获取用户类型，监控中心查下辖的单位，社会单位查自己，管理员查全部社会单位
        LoginUserVo loginUserVo=ShiroUtil.getUser();
        if(loginUserVo.getUserType()==0)
        {
            //获取所有
            List<Enterprise> eList=iEnterpriseService.getAllSocialUnit();
            list = eList.stream().map(Enterprise -> {
                return Enterprise.getId().toString();
            }).collect(Collectors.toList());
        }else{
            if(loginUserVo.getEnterpriseType() == 0)
            {

                list.add(loginUserVo.getEnterpriseId().toString());
            }else if (loginUserVo.getEnterpriseType() == 2)
            {
                List<Enterprise> eList=iEnterpriseService.queryUnitSelect(loginUserVo.getEnterpriseId().toString());
                list = eList.stream().map(Enterprise -> {
                    return Enterprise.getId().toString();
                }).collect(Collectors.toList());
            }

        }
        return  list;

    }
}
